/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cloudminga.database;

/**This class is created for getting the user's Personal details from table "Pomblast_User_tb"
 *by calling the Stored procedure sp_Pomblast_GetUserDetailsByUser
 * @author Shailendra
 */
import java.sql.*;
public class DataBase_UserInfo
{
    private String email_Id;
    private Connection connection;
    private CallableStatement callablestatement;
    private ResultSet resultSet;
    private ResultSetMetaData resultSet_MetaData;
    private int colCount;
    private int rowCount=0;
    private TableModel tableModel;
   
      public TableModel get_UserInfo(String email)
      {
        this.email_Id=email;
         try
          {
              Class.forName("net.sourceforge.jtds.jdbc.Driver");
              connection = DriverManager.getConnection("jdbc:jtds:sqlserver://mssql502.ixwebhosting.com/C230527_masterdatabase","C230527_sumit","Globus1234");
              callablestatement=connection.prepareCall("{call sp_Pomblast_GetUserDetailsByUser(?)}",ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
              callablestatement.setString(1, email_Id);
              resultSet=callablestatement.executeQuery();
              resultSet_MetaData=resultSet.getMetaData();
              colCount=resultSet_MetaData.getColumnCount();            
           }// End of try block
          catch(Exception exception)
          {
             exception.printStackTrace();
          }

            

          try
          {
           //tableModel=new TableModel(1, colCount);
            resultSet.last();
            rowCount=resultSet.getRow();
            resultSet.beforeFirst();
            System.out.println("number of rows are :  "+rowCount);
            tableModel=new TableModel(rowCount,colCount);
            resultSet.beforeFirst();
           if(resultSet.next())
            {
               for(int j=0;j<resultSet_MetaData.getColumnCount();j++)
               {
                   tableModel.setValueAt(0,j,resultSet.getString(j+1));
               }
           }
           else
           {
               System.out.println("invalid user");
           }

         }
           catch(Exception e)
           {
             e.printStackTrace();
           }
          return tableModel;  // Returns object of tablemodel in which row of data are stored
      }
  }

